import http from '@/utils/http'
export default {
  // 获取根文件夹列表
  async getRootFolders(data) {
    return await http.post('/api/folder/list', data)
  },
  //   获取根文件夹数目
  async getRootFoldersCount() {
    return await http.get('/api/folder/listCount')
  },
  //   创建根目录
  async addRootFolder(folderName) {
    return await http.post('/api/folder/insertOne/' + folderName)
  },

  //   获取子文件夹列表
  async getFolders(folderId, data) {
    return await http.post('/api/folder/list/' + folderId, data)
  },
  //   获取子文件夹总数
  async getFoldersCount(folderId) {
    return await http.get('/api/folder/selectCount/' + folderId)
  },
  //   创建子目录
  async addFolder(parentId, folderName) {
    return await http.post(
      '/api/folder/insertOne/' + parentId + '/' + folderName
    )
  },

  //   删除目录
  async deleteFolder(folderId) {
    return await http.post('/api/folder/deleteOne/' + folderId)
  },
  //   重命名目录
  async renameFolder(folderId, folderName) {
    return await http.post(
      '/api/folder/updateOne/' + folderId + '/' + folderName
    )
  },

  //   上传文件
  async uploadFile(folderId, file) {
    // 创建FormData对象
    const formdata = new FormData()
    // 将得到的文件流添加到FormData对象
    formdata.append('file', file, file.name)
    return await http({
      url: '/api/file/upload/' + folderId,
      data: formdata,
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data' // 值得注意的是，这个地方一定要把请求头更改一下
      }
    })
  },
  //   获取文件列表
  async getFileList(folderId, data) {
    return await http.post('/api/file/list/' + folderId, data)
  },
  //   获取文件总数
  async getFileCount(folderId) {
    return await http.get('/api/file/selectList/' + folderId)
  },
  //   下载文件
  async downloadFile(fileId) {
    return await http.post('/api/file/download/' + fileId)
  },
  //   移动文件
  async moveFile(oldFolderId, newFolderId, fileId) {
    return await http.post(
      '/api/file/move/' + oldFolderId + '/' + newFolderId + '/' + fileId
    )
  },
  //   复制文件
  async copyFile(folderId, fileId) {
    return await http.post('/api/file/copy/' + folderId + '/' + fileId)
  },

  //   收藏文件
  async collectFile(fileId) {
    return await http.post('/api/favorites/' + fileId)
  },
  //   分享文件
  async shareFile(userName, fileId) {
    return await http.post('/api/share/' + userName + '/' + fileId)
  },
  //   回收文件
  async deleteFile(fileId) {
    return await http.post('/api/recycle/' + fileId)
  }
}
